<!-- 这是一个带有回退功能的头部组件，组件的 Title 居中排列 -->
<template>
    <div class="container">
        <div class="header-item">
            <div class="left-icon"><el-icon @click.prevent="router.go(-1)"><ArrowLeftBold /></el-icon></div>
            <div class="title">{{ props.headerTitle.title }}</div>
            <div class="right-icon"></div>
        </div>
    </div>
</template>

<script setup name="backHeader">
import { onMounted } from 'vue';
import { useRouter } from 'vue-router';
const router = useRouter();
// 获取父组件传递来的值
const props = defineProps(['headerTitle']);
const alterBackgroundColor = () => {
    if(props.headerTitle.color){
        var element = document.getElementsByClassName('header-item');
        element[0].style.color = props.headerTitle.color;
    }
}
onMounted(() => {
    alterBackgroundColor();
})
</script>

<style scoped>
.container{
    width: 100%;
    height: 60px;
    background-color: #f5f5f5;
}
.header-item {
    width: 90%;
    height: 60px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #444;
    font-size: 20px;
    text-align: center;
    line-height: 60px;
}
.left-icon,
.right-icon {
    min-width: 30px;
    height: 60px;
}
.title {
    height: 60px;
}
</style>